<?php
namespace App\Services;
use App\Models\Notification;

class NotifyService {

    /**
     * store
     * @param $user_id
     * @param $type
     * @param $entity_id
     * @param $entity_user_id
     * @param null $content
     * @param $entity_type
     */
    public static function store($user_id, $type, $entity_id, $entity_user_id, $content = null, $entity_type = 0) {
        if ($user_id == $entity_user_id)
            return;

        $notify = Notification::where('user_id', $user_id)->where('entity_user_id', $entity_user_id)->first();
        //关注
        if ($notify) {
            if ($notify->type == 2 || $notify->type == 1) {
                $notify->delete();
            }
        }
        return Notification::create([
            'user_id' => $user_id,
            'type' => $type,
            'entity_id' => $entity_id,
            'entity_user_id' => $entity_user_id,
            'content' => $content,
            'entity_type' => $entity_type
        ]);
    }


    public static function storeSystem($user_id, $title, $content) {
        Notification::create([
            'entity_user_id' => $user_id,
            'is_system' => Notification::IS_SYSTEM,
            'title' => $title,
            'content' => $content
        ]);
    }

}
